home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Cream of the Crop 1
/
Cream of the Crop 1.iso
/
PROGRAM
/
LDB171.ARJ
/
FBINDER.HPP
< prev
next >
Wrap
C/C++ Source or Header
|
1992-05-12
|
9KB
|
391 lines
/*
FBinder.hpp -- Loose Data Binder v 1.7:
container class "form."
(C) Copyright 1992 John W. Small
All rights reserved
PSW / Power SoftWare
P.O. Box 10072
McLean, Virginia 22102 8072 USA
(703) 759-3838
If you want strong type checking and your compiler
doesn't support C++ templates, include the
following lines in your source code:
#define FType int
#define FBinder IntBdr
#define FBindeR IntBdR
#include "fbinder.hpp"
Replace "int" with the name of the data type you
want bound within the Binder and "IntBdr" with an
appropriate name for your new type of Binder and
"IntBdR" with the name of the pointer type to this
new Binder type. FType must have the following
properties to use this approach:
default constructor
copy initializer constructor,
i.e. TYPE(TYPE&)
destructor
assignment operator, i.e. operator=()
ostream& operator<<(ostream&,TYPE&)
istream& operator>>(istream&,TYPE&)
If not you must instead clone this file and
the fbinder.cpp file and use your editor to globally
replace: with something like:
FType int
FBinder IntBdr
FBindeR IntBdR
Suppose you called your two new files intbdr.hpp
and intbdr.cpp. Your can then further edit
intbdr.cpp to give your data type the appropriate
semantics:
edit: yielding properties:
Dassign assignment operator
Dnew copy initializer
Ddelete destructor
Dstore stream insert
Dload stream extract, default
construct
*/
#ifdef FType
#undef FBinder_HPP
#endif
#ifndef FBinder_HPP
#define FBinder_HPP
#ifndef BINDER_HPP
#include "binder.hpp"
#endif
typedef class FBinder * FBindeR;
#define FBindeR0 ((FBindeR)0)
class FBinder : Binder {
private:
/* FBinder-declared data members */
int initData(
/* FBinder-declared data
member initializers */
);
protected:
FBinder (initVFTs)
: Binder(initVFTsOnly) {}
Binder:: destruct;
virtual voiD Dassign(voiD D, const voiD S);
virtual voiD Dnew(const voiD D);
virtual void Ddelete(voiD D);
Binder:: Dattach;
Binder:: Ddetach;
Binder:: sberror;
Binder:: berror;
virtual void Dstore(ostream& os, voiD D);
virtual voiD Dload(istream& is);
virtual void store(ostream& os);
static FBindeR load(istream& is, FBindeR thiS);
Binder:: vload;
friend ostream& operator<<(ostream&,
FBinder&);
friend istream& operator>>(istream&,
FBindeR&);
public:
/* Constructors and destructor */
FBinder
(
/*
FBinder-declared data member
initializers go here!
*/
unsigned flags = BDR_BIND_ONLY,
unsigned maxNodes = BDR_MAXNODES,
unsigned limit = BDR_LIMIT,
unsigned delta = BDR_DELTA) :
Binder(flags,maxNodes,limit,delta)
{
(void) initData(
/* FBinder-declared data
member initializers */
);
}
FBinder
(FType * argv[],
unsigned argc = 0,
unsigned flags = BDR_BIND_ONLY)
: Binder((voiDV)argv,argc,flags) {}
FBinder
(const char *filename)
: Binder(initVFTsOnly)
{ (void) vload(filename,(BDRsloaD)
FBinder::load,this); }
Binder::save;
FType ** vector()
{ return (FType **)Binder::
vector(); }
virtual ~FBinder() { FBinder::destruct(); }
/* Housekeeping Primitives */
Binder:: Limit;
Binder:: setLimit;
Binder:: pack;
Binder:: Delta;
Binder:: setDelta;
Binder:: Nodes;
Binder:: MaxNodes;
Binder:: setMaxNodes;
Binder:: vacancy;
Binder:: vacancyNonElastic;
Binder:: Flags;
Binder:: setFlags;
Binder:: resetFlags;
FBinder& operator<<(FBinder& (*manipulator)
(FBinder&)) { return
(manipulator? (*manipulator)
(*this) : *this); }
/* Elastic Array Primitives */
FType * atIns(unsigned n, FType * D)
{ return (FType *)Binder::
atIns(n,(voiD)D); }
FType * atInsNew(unsigned n, const FType * D)
{ return (FType *)Binder::
atInsNew(n,(const voiD)D); }
FType * atRmv(unsigned n)
{ return (FType *)Binder::
atRmv(n); }
Binder:: allRmv;
Binder:: atDel;
FType * atDelAsg(unsigned n, FType * D)
{ return (FType *)Binder::
atDelAsg(n,(voiD)D); }
Binder:: allDel;
FType * atPut(unsigned n, FType * D)
{ return (FType *)Binder::
atPut(n,(voiD)D); }
FType * atPutNew(unsigned n, const FType * D)
{ return (FType *)Binder::
atPutNew(n,(const voiD)D); }
FType * atPutAsg(unsigned n, const FType * D)
{ return (FType *)Binder::
atPutAsg(n,(const voiD)D); }
FType * atGet(unsigned n)
{ return (FType *)Binder::
atGet(n); }
FType * operator[](unsigned n)
{ return atGet(n); }
FType * atGetAsg(unsigned n, FType * D)
{ return (FType *)Binder::
atGetAsg(n,(voiD) D); }
FType * atXchg(unsigned n, FType * D)
{ return (FType *)Binder::
atXchg(n,(voiD) D); }
unsigned index(const FType * D)
{ return Binder::
index((const voiD)D); }
Binder:: forEach;
/* Stack - Deque - Queue Primitives */
FType * push(FType * D)
{ return (FType *)Binder::
push((voiD) D); }
FType * pushNew(const FType * D)
{ return (FType *)Binder::
pushNew((const voiD)D); }
FType * pop()
{ return (FType *)Binder::
pop(); }
FBinder& operator>>(FType *& D)
{ D = atRmv(0); return *this; }
Binder:: popDel;
FType * popDelAsg(FType * D)
{ return (FType *)Binder::
popDelAsg((voiD)D); }
FType * top()
{ return (FType *)Binder::
top(); }
FType * topAsg(FType * D)
{ return (FType *)Binder::
topAsg((voiD)D); }
FType * insQ(FType * D)
{ return (FType *)Binder::
insQ((voiD)D); }
FBinder& operator<<(FType * D)
{ atIns(Nodes(),D); return *this; }
FType * insQNew(const FType * D)
{ return (FType *)Binder::
insQNew((const voiD)D); }
FType * unQ()
{ return (FType *)Binder::
unQ(); }
Binder:: unQDel;
FType * unQDelAsg(FType * D)
{ return (FType *)Binder::
unQDelAsg((voiD)D); }
FType * rear()
{ return (FType *)Binder::
rear(); }
FType * rearAsg(FType * D)
{ return (FType *)Binder::
rearAsg((voiD)D); }
/* List (single and double linked) Primitives */
Binder:: CurNode;
Binder:: setCurNode;
FType * ins(FType * D)
{ return (FType *)Binder::
ins((voiD)D); }
FType * insNew(const FType * D)
{ return (FType *)Binder::
insNew((const voiD)D); }
FType * rmv()
{ return (FType *)Binder::
rmv(); }
Binder:: del;
FType * delAsg(FType * D)
{ return (FType *)Binder::
delAsg((voiD)D); }
FType * put(FType * D)
{ return (FType *)Binder::
put((voiD)D); }
FType * putNew(const FType * D)
{ return (FType *)Binder::
putNew((const voiD)D); }
FType * putAsg(const FType * D)
{ return (FType *)Binder::
putAsg((const voiD)D); }
FType * get()
{ return (FType *)Binder::
get(); }
operator FType *() { return get(); }
FType * getAsg(FType * D)
{ return (FType *)Binder::
getAsg((voiD)D); }
FType * next()
{ return (FType *)Binder::
next(); }
FType * operator++()
{ return next(); }
FType * nextAsg(FType * D)
{ return (FType *)Binder::
nextAsg((voiD)D); }
FType * prev()
{ return (FType *)Binder::
prev(); }
FType * operator--()
{ return prev(); }
FType * prevAsg(FType * D)
{ return (FType *)Binder::
prevAsg((voiD)D); }
FType * firstThat(BDRdetecT B, voiD M = voiD0)
{ return (FType *)Binder::
firstThat(B,M); }
FType * lastThat(BDRdetecT B, voiD M = voiD0)
{ return (FType *)Binder::
lastThat(B,M); }
/* Priority Q, Set, Bag, Dictionary, Sort Primitives */
Binder:: Sorted;
Binder:: unSort;
Binder:: setComP;
Binder:: ComP;
Binder:: sort;
FType * insSort(FType * D)
{ return (FType *)Binder::
insSort((voiD)D); }
FType * insSortNew(const FType * D)
{ return (FType *)Binder::
insSortNew((const voiD)D); }
FType * insUnique(FType * D)
{ return (FType *)Binder::
insUnique((voiD)D); }
FType * insUniqueNew(const FType * D)
{ return (FType *)Binder::
insUniqueNew((const voiD)D); }
FType * findFirst(const FType * K)
{ return (FType *)Binder::
findFirst((const voiD)K); }
FType * findNext(const FType * K)
{ return (FType *)Binder::
findNext((const voiD)K); }
FType * findLast (const FType * K)
{ return (FType *)Binder::
findLast((const voiD)K); }
FType * findPrev(const FType * K)
{ return (FType *)Binder::
findPrev((const voiD)K); }
unsigned findAll(const FType * K)
{ return Binder::
findAll((const voiD)K); }
}; /* class FBinder */
inline ostream& operator<<(ostream& os, FBinder& b)
{
if (b.Flags(BDR_DSTORE))
b.store(os);
return os;
}
inline istream& operator>>(istream& is, FBindeR& B)
{ B = FBinder::
load(is,FBindeR0);
return is; }
#endif /* FBinder_HPP */
#ifdef FType
#include "fbinder.cpp"
#undef FType
#undef FBinder
#undef FBindeR
#endif